<template>
    <el-form ref="refBugWorkSheetForm" :model="bugWorkSheetForm" :rules="rules" label-width="80px">
        <el-form-item label="问题详情" prop="bug_info">
            <u-editor ref="bugInfoEditorContainer" disabled :value="bugWorkSheetForm.bug_info" />
<!--            :style="editorStyle"-->
        </el-form-item>
        <el-form-item v-if="type === 'handler' || type === 'detail'" label="处理详情" prop="deal_info">
            <u-editor ref="dealInfoEditorContainer" :value="bugWorkSheetForm.deal_info" />
<!--            :style="editorStyle"-->
        </el-form-item>
    </el-form>
</template>

<script>
export default {
    name: "BugWorkSheetForm",
    components: {
        UEditor: () => import('@common/components/UEditor'),
    },
    props: {
        propsData: {
            type: Object,
            default() {
                return {
                    init: true,
                };
            },
        },
    },
    data() {
        let _this = this;
        return {
            type: 'add',
            editorStyle: {},
            dataTypeList: [
                {
                    value: 1,
                    label: '使用者',
                },
                {
                    value: 2,
                    label: '平台',
                },
            ],
            rules: {
            },
            bugWorkSheetForm: {},
        }
    },
    watch: {
        propsData: {
            handler() {
                this.init();
            },
            deep: true,
            immediate: true,
        },
    },
    mounted() {
        // this.$on('copy', (res) => {
        //     let a = 9;
        //     debugger
        // });
        // window.addEventListener("copy",  (e) => {
        //     debugger
        //     if (!(e.clipboardData && e.clipboardData.items)) {
        //         return;
        //     }
        //     for (let i = 0, len = e.clipboardData.items.length; i < len; i++){
        //         let itemz = e.clipboardData.items[i];
        //         if (itemz.kind === "string") {
        //             itemz.getAsString(function (str) {
        //                 //  alert(str);
        //             });
        //         }  else if(itemz.kind === "file") {
        //             let pasteFile = itemz.getAsFile();
        //             alert(pasteFile);
        //         }
        //
        //     }
        // });
    },
    methods: {
        // 初始化
        init() {
            let _this = this;
            _this.bugWorkSheetForm = {};
            if (_this.$utils.isNotEmpty(_this.propsData.type)) {
                _this.type = _this.propsData.type;
                // state 0-处理 1-处理中 2-关闭
                if (_this.propsData.row) {
                    if (_this.type === 'handler') {
                        // 处理回复问题工单
                        _this.bugWorkSheetForm =  {
                            state: 2,
                            parent_sid: _this.propsData.row.sid,
                            account_sid: _this.propsData.row.account_sid,
                            bug_info: _this.propsData.row.bug_info,
                        };
                    } else if (_this.type === 'edit' ){
                        // 编辑问题工单
                        _this.bugWorkSheetForm = _this.propsData.row;
                    } else if (_this.type === 'detail') {
                        // 问题工单处理详情
                        _this.bugWorkSheetForm = _this.propsData.row;
                    }
                } else {
                    // 添加问题工单
                    _this.bugWorkSheetForm = {
                        parent_sid: -1,
                        state: 0,
                    };
                }
            }
            // _this.editorStyle = $.extend({}, _this.getEditorStyle());
        },
        //
        // getEditorStyle() {
        //     let root = $(this.getActiveTabsContainer());
        //     let tabHeight = $(root).outerHeight();
        //     let titleHeight = $(root).find('.cms_content_container .title_area').outerHeight();
        //     let btnHeight = $(root).find('.cms_content_container .title_area').outerHeight();
        //     return {
        //         maxHeight: `${ tabHeight - titleHeight - btnHeight - 87 }px`,
        //     };
        // },
        // 保存
        async handleSaveBugWorkSheet() {
            const _this = this;
            const valid = await _this.$refs['refBugWorkSheetForm'].validate();
            if (valid) {
                let params = $.extend({}, _this.bugWorkSheetForm);
                if (_this.$refs["bugInfoEditorContainer"]) {
                    params.bug_info = _this.$refs["bugInfoEditorContainer"].getContent();
                }
                if (_this.$refs["dealInfoEditorContainer"]) {
                    params.deal_info = _this.$refs["dealInfoEditorContainer"].getContent();
                }
                return _this.fetchData(_this.$api.API_SaveSysBugWorksheet, params).then(res => {
                    _this.$message.success('保存成功！');
                    return true;
                }).catch(() => {
                    return false;
                });
            } else {
                _this.$message.warning('请按提示填写信息！');
            }
        },
    },
}
</script>

<style scoped>

</style>
